/**
 * @Description 宿舍管理dao层
 * @author 20155870 杨润增
 * @create 2018-04-12 14:07
 **/
package com.campus_information_portal.dao;
import com.campus_information_portal.entity.DorStuTerm;
import com.campus_information_portal.entity.DormitoryApplyForm;
import org.apache.ibatis.annotations.*;
import java.util.Date;
import java.util.List;

/**
 * @author 20155870 杨润增
 * @className DormitoryDao
 * @Description 宿舍管理dao层
 * @create 2018-04-12 14:07
 **/
public interface DormitoryDao {

    /**
     * @param
     * @Description 查找全部留宿申请信息
     * @author 20155870 杨润增
     * @methodName queryAllDormitoryApplyForm
     * @returnType list
     * @create 2018/4/12 14:13
     **/
    @Select("select * from dormitory_apply_form")
    List<DormitoryApplyForm> queryAllDormitoryApplyForm();

    /**
     * @param
     * @Description 查找全部留宿申请信息
     * @author 20155870 杨润增
     * @methodName queryAllDormitoryApplyForm
     * @returnType list
     * @create 2018/4/12 14:13
     **/
    @Select("select dormitory_apply_form.* , student.stu_num ,student.stu_name,student.academy_id,term.term_num,term.term_year,academy.academy_name " +
            "from dormitory_apply_form ,student,term,academy " +
            "WHERE dormitory_apply_form.stu_info_id=student.stu_info_id " +
            "AND dormitory_apply_form.term_id=term.term_id " +
            "AND student.academy_id=academy.academy_id")
    List<DorStuTerm> queryAllDormitoryApplyForm_2();


    /**
     * @param dormitory_apply_form_id
     * @Description 根据申请表id查询一个申请信息
     * @author 20155870 杨润增
     * @methodName queryDormitoryApplyFormById
     * @returnType DormitoryApplyForm
     * @create 2018/4/12 14:18
     **/
    @Select("select * from dormitory_apply_form where dormitory_apply_form_id=#{dormitory_apply_form_id}")
    DormitoryApplyForm queryDormitoryApplyFormById(@Param("dormitory_apply_form_id") int dormitory_apply_form_id);

    /**
     * @param term_id
     * @Description 根据学期查询一个申请信息
     * @author 20155870 杨润增
     * @methodName queryDormitoryApplyFormByTermId
     * @returnType DormitoryApplyForm
     * @create 2018/4/12 14:27
     **/
    @Select("select * from dormitory_apply_form where term_id=#{term_id}")
    DormitoryApplyForm queryDormitoryApplyFormByTermId(@Param("term_id") int term_id);

    /**
     * @param stu_info_id
     * @Description 根据学生id查询一个申请信息
     * @author 20155870 杨润增
     * @methodName queryDormitoryApplyFormByStu_info_id
     * @returnType DormitoryApplyForm
     * @create 2018/4/12 14:28
     **/
    @Select("select * from dormitory_apply_form where stu_info_id=#{stu_info_id}")
    DormitoryApplyForm queryDormitoryApplyFormByStu_info_id(@Param("stu_info_id") int stu_info_id);


    /**
     * @param
     * @Description 增加一条留宿申请
     * @author 20155870 杨润增
     * @methodName addApply
     * @returnType int
     * @create 2018/5/3 8:33
     **/
    @Insert("insert into dormitory_apply_form(dormitory_apply_form_id,term_id,stu_info_id,dormitory_num,apply_date,apply_reason,start_date,end_date,apply_state) " +
            "values(NULL,#{termId},#{stuInfoId},#{dormitoryNum},#{applyDate},#{applyReason},#{startDate},#{endDate},#{applyState})")

    /*@Insert("insert into dormitory_apply_form (term_id,stu_info_id,dormitory_num,apply_date,apply_reason,start_date,end_date,apply_state)" +
            "values(#{term_id},#{stuInfoId},#{dormitoryNum},#{applyDate},#{applyReason},#{startDate},#{endDate},#{applyState})")
    @Options(useGeneratedKeys = true,keyProperty = "DormitoryApplyForm.dormitoryApplyFormId")*/
    int addApply(@Param("termId") int termId, @Param("stuInfoId") int stuInfoId,
                 @Param("dormitoryNum") int dormitoryNum, @Param("applyDate") Date applyDate,
                 @Param("applyReason") String applyReason, @Param("startDate") Date startDate,
                 @Param("endDate") Date endDate, @Param("applyState") int applyState);


    @Insert("insert into dormitory_apply_form(dormitory_apply_form_id,term_id,stu_info_id,dormitory_num,apply_date,apply_reason,start_date,end_date,apply_state) " +
            "values(NULL,#{termId},#{stuInfoId},#{dormitoryNum},#{applyDate},#{applyReason},#{startDate},#{endDate},#{applyState})")
    int addApply_2(DormitoryApplyForm dormitoryApplyForm);


   // int addApply(@Param("dormitoryApplyForm")DormitoryApplyForm dormitoryApplyForm);

    /**
     * @param dormitoryApplyFormId
     * @Description 同意申请
     * @author 20155870 杨润增
     * @methodName agreeApply
     * @returnType int
     * @create 2018/5/3 8:34
     **/
    @Update("update dormitory_apply_form set apply_state=1 where dormitory_apply_form_id = #{dormitoryApplyFormId}")
    int agreeApply(@Param("dormitoryApplyFormId") int dormitoryApplyFormId);

    /**
     * @param dormitoryApplyFormId
     * @Description 拒绝申请
     * @author 20155870 杨润增
     * @methodName refuseApply
     * @returnType int
     * @create 2018/5/3 8:34
     **/
    @Update("update dormitory_apply_form set apply_state=0 where dormitory_apply_form_id = #{dormitoryApplyFormId}")
    int refuseApply(@Param("dormitoryApplyFormId") int dormitoryApplyFormId);

    /**
     * @param dormitory_apply_form_id
     * @Description 删除一个申请
     * @author 20155870 杨润增
     * @methodName deleteApply
     * @returnType int
     * @create 2018/5/3 8:35
     **/
    @Delete("delete from dormitory_apply_form  where dormitory_apply_form_id = #{dormitory_apply_form_id}")
    int deleteApply(@Param("dormitory_apply_form_id") int dormitory_apply_form_id);





    @SelectProvider(type = DormitorySqlProvider.class, method = "query")
    List<DormitoryApplyForm> query(DormitoryApplyForm dormitoryApplyForm);


    /**
     * @param dorStuTerm
     * @Description 多条件查询
     * @author 20155870 杨润增
     * @methodName queryApplyByConditions
     * @returnType List
     * @create 2018/5/6 14:05
     **/
    @SelectProvider(type = DormitorySqlProvider.class, method = "queryApplyByConditions")
    List<DorStuTerm> queryApplyByConditions(DorStuTerm dorStuTerm);

    /**
     * @Description 根据stu_info_id查询dormitory_num
     * @author 20155870 杨润增
     * @methodName queryDormitoryNumByStuInfoId
     * @param stuInfoId
     * @returnType DormitoryApplyForm
     * @create 2018/5/18 16:24
     **/
    @Select("select dormitory_num from dormitory_apply_form where stu_info_id=#{stuInfoId}")
    DormitoryApplyForm queryDormitoryNumByStuInfoId(@Param("stuInfoId") int stuInfoId);
}
